home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / LOG.C < prev    next >
Text File  |  1987-06-18  |  2KB  |  63 lines

  1.  
  2. /***********************************************************
  3.  *               The TULSA IBM C BOARD                     *
  4.  *                   918-664-8737                          *
  5.  *             300/1200 XMODEM, 24 Hours                   *
  6.  **********************************************************/
  7.  
  8.  
  9. #include "math.h"
  10. #include "errno.h"
  11.  
  12. double log10(x)
  13. double x;
  14. {
  15.         return log(x)*0.43429448190325182765;
  16. }
  17.  
  18. #define A0 -0.64124943423745581147e+2
  19. #define A1 +0.16383943563021534222e+2
  20. #define A2 -0.78956112887491257267e+0
  21. #define A(w) ((A2*w A1)*w A0)
  22.  
  23. #define B0 -0.76949932108494879777e+3
  24. #define B1 +0.31203222091924532844e+3
  25. #define B2 -0.35667977739034646171e+2
  26. #define B(w) (((w B2)*w B1)*w B0)
  27.  
  28. #define C0 0.70710678118654752440
  29. #define C1 0.693359375
  30. #define C2 -2.121944400546905827679e-4
  31.  
  32. double log(x)
  33. double x;
  34. {
  35.         double Rz, f, z, w, znum, zden, xn;
  36.         int n;
  37.         extern int errno;
  38.  
  39.         if (x <= 0.0) {
  40.                 errno = EDOM;
  41.                 return -HUGE;
  42.         }
  43.         f = frexp(x, &n);
  44.         if (f > C0) {
  45.                 znum = (znum = f-0.5) - 0.5; /* the assignment prevents const. eval */
  46.                 zden = f*0.5 + 0.5;
  47.         } else {
  48.                 --n;
  49.                 znum = f - 0.5;
  50.                 zden = znum*0.5 + 0.5;
  51.         }
  52.         z = znum/zden;
  53.         w = z*z;
  54. /* the lines below are split up to allow expansion of A(w) and B(w) */
  55.         Rz = z + z * (w *
  56.                          A(w)
  57.                         /B(w));
  58.         xn = n;
  59.         return (xn*C2 + Rz) + xn*C1;
  60. }
  61.  
  62.  
  63.